package com.anyou.mall.use.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.use.domain.UserAddress;
import com.anyou.mall.use.service.IUserAddressService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 用户收货地址Controller
 *
 * @author gaochaohao
 * @date 2022-03-22
 */
@Api(tags = "用户收货地址")
@RestController
@RequestMapping("/use/userAddress")
public class UserAddressController extends BaseController
{
    @Autowired
    private IUserAddressService userAddressService;

    /**
     * 查询用户收货地址列表
     */
    @ApiOperation("查询用户收货地址列表")
    @PreAuthorize("@ss.hasPermi('use:userAddress:list')")
    @GetMapping("/list")
    public TableDataInfo<List<UserAddress>> list(UserAddress userAddress)
    {
        startPage();
        List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户收货地址列表
     */
    @ApiOperation("导出用户收货地址列表")
    @PreAuthorize("@ss.hasPermi('use:userAddress:export')")
    @Log(title = "用户收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAddress userAddress)
    {
        List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
        ExcelUtil<UserAddress> util = new ExcelUtil<UserAddress>(UserAddress.class);
        util.exportExcel(response, list, "用户收货地址数据");
    }

    /**
     * 获取用户收货地址详细信息
     */
    @ApiOperation("获取用户收货地址详细信息")
    @PreAuthorize("@ss.hasPermi('use:userAddress:query')")
    @GetMapping(value = "/{addressId}")
    public ApiResult<UserAddress> getInfo(@PathVariable("addressId") Long addressId)
    {
        return ApiResult.success(userAddressService.selectUserAddressByAddressId(addressId));
    }

    /**
     * 新增用户收货地址
     */
    @ApiOperation("新增用户收货地址")
    @PreAuthorize("@ss.hasPermi('use:userAddress:add')")
    @Log(title = "用户收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody UserAddress userAddress)
    {
        return ApiResult.success(userAddressService.insertUserAddress(userAddress));
    }

    /**
     * 修改用户收货地址
     */
    @ApiOperation("修改用户收货地址")
    @PreAuthorize("@ss.hasPermi('use:userAddress:edit')")
    @Log(title = "用户收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody UserAddress userAddress)
    {
        return ApiResult.success(userAddressService.updateUserAddress(userAddress));
    }

    /**
     * 删除用户收货地址
     */
    @ApiOperation("删除用户收货地址")
    @PreAuthorize("@ss.hasPermi('use:userAddress:remove')")
    @Log(title = "用户收货地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{addressIds}")
    public ApiResult remove(@PathVariable Long[] addressIds)
    {
        return ApiResult.success(userAddressService.deleteUserAddressByAddressIds(addressIds));
    }
}
